package us.ajg0702.leaderboards.libs.hikari.metrics.prometheus;

import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Counter;
import io.prometheus.client.Histogram;
import us.ajg0702.leaderboards.libs.hikari.metrics.IMetricsTracker;


class PrometheusHistogramMetricsTracker
        implements IMetricsTracker {
    private static final Counter CONNECTION_TIMEOUT_COUNTER = ((Counter.Builder) ((Counter.Builder) ((Counter.Builder) Counter.build()
            .name("hikaricp_connection_timeout_total"))
            .labelNames(new String[]{"pool"
            })).help("Connection timeout total count"))
            .create();


    private static final Histogram ELAPSED_ACQUIRED_HISTOGRAM = registerHistogram("hikaricp_connection_acquired_nanos", "Connection acquired time (ns)", 1000.0D);


    private static final Histogram ELAPSED_BORROWED_HISTOGRAM = registerHistogram("hikaricp_connection_usage_millis", "Connection usage (ms)", 1.0D);


    private static final Histogram ELAPSED_CREATION_HISTOGRAM = registerHistogram("hikaricp_connection_creation_millis", "Connection creation (ms)", 1.0D);
    private final Counter.Child connectionTimeoutCounterChild;
    private final Histogram.Child elapsedAcquiredHistogramChild;
    private final Histogram.Child elapsedBorrowedHistogramChild;
    private final Histogram.Child elapsedCreationHistogramChild;
    PrometheusHistogramMetricsTracker(String poolName, CollectorRegistry collectorRegistry) {
        registerMetrics(collectorRegistry);
        this.connectionTimeoutCounterChild = (Counter.Child) CONNECTION_TIMEOUT_COUNTER.labels(new String[]{poolName});
        this.elapsedAcquiredHistogramChild = (Histogram.Child) ELAPSED_ACQUIRED_HISTOGRAM.labels(new String[]{poolName});
        this.elapsedBorrowedHistogramChild = (Histogram.Child) ELAPSED_BORROWED_HISTOGRAM.labels(new String[]{poolName});
        this.elapsedCreationHistogramChild = (Histogram.Child) ELAPSED_CREATION_HISTOGRAM.labels(new String[]{poolName});
    }

    private static Histogram registerHistogram(String name, String help, double bucketStart) {
        return ((Histogram.Builder) ((Histogram.Builder) ((Histogram.Builder) Histogram.build()
                .name(name))
                .labelNames(new String[]{"pool"
                })).help(help))
                .exponentialBuckets(bucketStart, 2.0D, 11)
                .create();
    }

    private void registerMetrics(CollectorRegistry collectorRegistry) {
        CONNECTION_TIMEOUT_COUNTER.register(collectorRegistry);
        ELAPSED_ACQUIRED_HISTOGRAM.register(collectorRegistry);
        ELAPSED_BORROWED_HISTOGRAM.register(collectorRegistry);
        ELAPSED_CREATION_HISTOGRAM.register(collectorRegistry);
    }


    public void recordConnectionAcquiredNanos(long elapsedAcquiredNanos) {
        this.elapsedAcquiredHistogramChild.observe(elapsedAcquiredNanos);
    }


    public void recordConnectionUsageMillis(long elapsedBorrowedMillis) {
        this.elapsedBorrowedHistogramChild.observe(elapsedBorrowedMillis);
    }


    public void recordConnectionCreatedMillis(long connectionCreatedMillis) {
        this.elapsedCreationHistogramChild.observe(connectionCreatedMillis);
    }


    public void recordConnectionTimeout() {
        this.connectionTimeoutCounterChild.inc();
    }
}


*Location:D:\User\Xuan\Downloads\ajLeaderboards-1.3.3.jar\\us\ajg0702\leaderboards\libs\hikari\metrics\prometheus\PrometheusHistogramMetricsTracker.class
 *Java compiler version:8(52.0)
         *JD-Core Version:1.1.3
